//
//  KLInstructionsViewController.m
//  KISSLOCK
//
//  Created by 陈宾鹏 on 16/6/15.
//  Copyright © 2016年 陈宾鹏. All rights reserved.
//

#import "KLInstructionsViewController.h"
#import "KLHelp.h"
#import "HemaConst.h"
#import "Masonry.h"
#import "JRToast.h"
#import "KLHttpAPI.h"

@interface KLInstructionsViewController ()<UIScrollViewDelegate,UIWebViewDelegate>
{
    UIScrollView *scrollView;
}

@property(nonatomic,strong)UIWebView *myWebView;
@end

@implementation KLInstructionsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //设置导航栏
    [self naveSet];
    
    _myWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, UI_View_Width, UI_View_Height-55)];
    _myWebView.delegate = self;
   
    [_myWebView setScalesPageToFit:NO];
    
    [self.view addSubview:_myWebView];
    NSString *path;
    if(self.whichWeb == 1){//注册声明
        self.title =@"注册声明";
        path = [NSString stringWithFormat:@"http://%@/hm_kisslock/TextualDescription/LegalStatement.html",HTTP_SERVER_ADDRESS];
    }else if(self.whichWeb == 2){//使用说明
        self.title =@"使用说明";
        path = [NSString stringWithFormat:@"http://%@/hm_kisslock/TextualDescription/help.html",HTTP_SERVER_ADDRESS];
    }else if (self.whichWeb == 3){//相关政策
        self.title =@"相关政策";
        path = [NSString stringWithFormat:@"http://%@/hm_kisslock/TextualDescription/LegalStatement.html",HTTP_SERVER_ADDRESS];
    }
    
    [_myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:path]]];
    
}

#pragma mark -webview代理
-(void)webViewDidStartLoad:(UIWebView*)webView{
    //当网页视图已经开始加载一个请求后，得到通知。
    [KLHelp showHUDAddedTo:self.view animated:YES];
}

-(void)webViewDidFinishLoad:(UIWebView*)webView{
    //当网页视图结束加载一个请求之后，得到通知。
    [KLHelp hideAllHUDsForView:self.view animated:YES];
}

-(void)webView:(UIWebView*)webView DidFailLoadWithError:(NSError*)error{
    //当在请求加载中发生错误时，得到通知。会提供一个NSSError对象，以标识所发生错误类型。
    [KLHelp hideAllHUDsForView:self.view animated:YES];
    [JRToast showWithText:@"网页加载出错!"];
}

#pragma mark - 初始化导航栏
-(void)naveSet{
    self.view.backgroundColor = [UIColor whiteColor];
    [KLHelp navSet:self doBackHandeler:^(UIButton *backButton) {
        [backButton addTarget:self action:@selector(doBack:) forControlEvents:UIControlEventTouchUpInside];
    }];
}-(void)doBack:(id)sender{
    [self.navigationController popViewControllerAnimated:YES];
}
@end
